function countup(n) {
  if (n < 1) {
    return [];
  } else {
    console.log("n", n);
    const countArray = countup(n - 1);
    console.log("before", countArray);
    countArray.push(n);
    console.log("after", countArray);

    return countArray;
  }
}

function countupdemo(n) {
  if (n < 1) {
    return [];
  } else {
    console.log("n", n);
    const countArray = function countupdemo(n = 2) {
      if (n < 1) {
        return [];
      } else {
        console.log("n", n);
        const countArray = function countupdemo(n = 1) {
          if (n < 1) {
            return [];
          } else {
            console.log("n", n);
            const countArray = [];
            console.log("before", countArray);
            countArray.push(n);
            console.log("after", countArray);

            return countArray;
          }
        };
        console.log("before", countArray);
        countArray.push(n);
        console.log("after", countArray);

        return [];
      }
    };
    console.log("before", countArray);
    countArray.push(n);
    console.log("after", countArray);

    return countArray;
  }
}
console.log(countup(5)); // [ 1, 2, 3, 4, 5 ]
